In Class Exercise 5

A short description of the post.

Sarah Chin linkedin.com/in/sarahchin99/
09-13-2021

Installing and Loading the R package

Importing Geospatial data

Importing shapefile using st_read() of sf package. The output object is in tibble sf object class.

Reading layer `MP14_SUBZONE_WEB_PL' from data source 
  `D:\sarahcsp\IS415_blog\_posts\2021-09-13-in-class-exercise\data\shapefile' 
  using driver `ESRI Shapefile'
Simple feature collection with 323 features and 15 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 2667.538 ymin: 15748.72 xmax: 56396.44 ymax: 50256.33
Projected CRS: SVY21

Projection is in SVY21.

Importing Aspatial data

read_rds() of readr package is used instead of readRDS() of base R is used. This is because output of read_RDS is in tibble object.

Note that there are some data issue in childcare data frame because ‘Lat’ and ‘Lng’ should be in numeric data type.

Converting the aspatial data frame into sf objects

Note: st_as_sf accept coordinates in character data type.

If you want to change the ‘Lat’ and ‘Lng’ in the original dataset to numeric data type, it is also acceptable.

Plot map to review

You can also view more than one data in a single map.

Geospatial Data Wrangling

Converting from sf to Spatial dataframe classes

as_Spatial() of sf package.

Converting Spatial data frame into Spatial objects

as.SpatialPoint() of as.SpatialPolygon() of maptools package.

Note that it is no longer a dat frame, it is a formal class. Compare it to childcare and you realise that the data has been dropped from childcare_sp.

Converting from Spatial Objects into ppp objects

Dropping all the projection information. All that would be left is the coordinates.

Removing duplicate points using jitter

[1] FALSE